package top.idetect.client.modules.cloth.controller;


import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import top.idetect.client.common.api.CommonResult;
import top.idetect.client.modules.cloth.model.DynamicConfig;
import top.idetect.client.modules.cloth.service.DynamicConfigService;

import static top.idetect.client.schedule.IpUpdateTask.ipList;

/**
 * <p>
 * 动态配置表 前端控制器
 * </p>
 *
 * @author wjh
 * @since 2024-04-11
 */
@RestController
@RequestMapping("/dynamicConfig")
public class DynamicConfigController {

    @Autowired
    private DynamicConfigService dynamicConfigService;

    @ApiOperation("根据配置名查询数组格式的配置值")
    @GetMapping("/getArrayByName")
    @ResponseBody
    public CommonResult getArrayByName(@RequestParam String configName) {
        DynamicConfig config = dynamicConfigService.getByConfigName(configName);
        String[] split = config.getConfigValue().split(",");

        return CommonResult.success(split);
    }

    @ApiOperation("根据配置名查询配置")
    @GetMapping("/getByName")
    @ResponseBody
    public CommonResult getByName(@RequestParam String configName) {
        DynamicConfig config = dynamicConfigService.getByConfigName(configName);
        return CommonResult.success(config);
    }

}

